<?php namespace Common\Model;
use Hdphp\Model\Model;
class Login extends Model{
	protected $table = 'quser';
	protected $auto = [
        ['qpassword','md5','function',3,3]
    ];
	
	protected $validate = [
        ['qusername','required','用户名必填',3,3],
        ['qusername','_username','用户名或者密码输入不正确',3,3],
        ['qpassword','required','密码必填',3,3],
        ['qpassword','_pass','用户名或者密码输入不正确',3,3],
        ['code','required','验证码必填',3,3],
        ['code','_code','验证码不正确',3,3],    
    ];
	
	public function _code(){
        $code = Q('post.code');
        if(strtolower($code) != strtolower($_SESSION['code'])){
            return false;
        }
        return true;
    }
	
	public function _username(){
        $qusername = Q('post.qusername');
        $data = $this->where(['qusername'=>$qusername])->find();
		$qpassword=Q('post.qpassword',0,'md5');
        if($data['qpassword'] != $qpassword){
        	return false;
        }
		return true;
    }
	
	public function login(){
		if(!$this->create()) return false;
		return true;
	}
}
